package com.lh.controller;



import com.lh.commonutils.R;
import com.lh.entity.EduChapter;
import com.lh.service.IEduChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author yms
 * @since 2021-06-05
 */
@RestController
@RequestMapping("/eduservice/edu-chapter")
//@CrossOrigin
@Api(value = "章节管理")
public class EduChapterController {

    @Resource
    private IEduChapterService chapterService;



    @ApiOperation(value = "课程大纲列表")
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId){
       R  r=chapterService.getChapterVideo(courseId);
        return r;
    }

    @ApiOperation(value = "添加章节")
    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter chapter){
        boolean b = chapterService.save(chapter);
        if (b){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation(value = "根据id查询章节")
    @GetMapping("getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId){

        EduChapter chapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",chapter);

    }

    @ApiOperation(value = "修改章节")
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter chapter){
        boolean b = chapterService.updateById(chapter);
        if (b){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @DeleteMapping("{chapterId}")
    @ApiOperation(value = "删除章节")
    public R deleteChapter(@PathVariable String chapterId){

        R r = chapterService.deleteChapter(chapterId);

        return r;

    }


}

